let obj = {
  //标点错误列表
  errorBiaoDians: [
    {
      ziSIndex: 98,
      ziEIndex: 105,
      type: "对话标点缺失",
      code: "BD001", //type对应的编码
      correct: "妈笑着说：\"你小心点呀！\"",
      reason: "在引用人物对话时，冒号后面应加上前引号，使句子标点完整。",
      locations: [
        { imageIndex: 0, t: 540, l: 351, w: 42, h: 70 },
        { imageIndex: 0, t: 540, l: 402, w: 75, h: 70 },
        { imageIndex: 0, t: 540, l: 486, w: 54, h: 70 },
        { imageIndex: 0, t: 540, l: 549, w: 45, h: 70 },
        { imageIndex: 0, t: 540, l: 603, w: 63, h: 70 },
        { imageIndex: 0, t: 540, l: 675, w: 45, h: 70 },
        { imageIndex: 0, t: 541, l: 729, w: 42, h: 69 },
        { imageIndex: 0, t: 541, l: 780, w: 61, h: 69 },
      ],
    },
    {
      ziSIndex: 155,
      ziEIndex: 155,
      type: "标点使用不当",
      code: "BD002",
      correct: "我咬了一大口面包，突然一阵风吹来",
      reason: "此处用逗号更能体现句子的停顿和语义的连贯，顿号使用不当。",
      locations: [{ imageIndex: 0, t: 799, l: 798, w: 35, h: 73 }],
    },
    {
      ziSIndex: 283,
      ziEIndex: 283,
      type: "标点使用不当",
      code: "BD003",
      correct: "我照他说的做，果然成功了",
      reason: "此处用逗号更合适，顿号不能准确表达句子的停顿和语义关系。",
      locations: [{ imageIndex: 0, t: 1411, l: 847, w: 46, h: 67 }],
    },
  ],
  //词语错误列表
  errorCiYus: [
    {
      ziSIndex: 106,
      ziEIndex: 123,
      type: "关联词使用不当",
      code: "CY001",
      ciYu: "有面包、苹果,和果汁",
      correct: "有面包、苹果和果汁",
      reason: "\"和\"前面的逗号多余，应删去。",
      locations: [
        { imageIndex: 0, t: 624, l: 232, w: 53, h: 74 },
        { imageIndex: 0, t: 624, l: 295, w: 45, h: 74 },
        { imageIndex: 0, t: 624, l: 350, w: 57, h: 74 },
        { imageIndex: 0, t: 624, l: 417, w: 60, h: 74 },
        { imageIndex: 0, t: 624, l: 486, w: 46, h: 74 },
        { imageIndex: 0, t: 624, l: 541, w: 70, h: 74 },
        { imageIndex: 0, t: 624, l: 620, w: 46, h: 74 },
        { imageIndex: 0, t: 624, l: 675, w: 48, h: 74 },
        { imageIndex: 0, t: 624, l: 733, w: 46, h: 74 },
        { imageIndex: 0, t: 624, l: 788, w: 70, h: 74 },
        { imageIndex: 0, t: 625, l: 867, w: 48, h: 74 },
        { imageIndex: 0, t: 625, l: 922, w: 36, h: 74 },
        { imageIndex: 0, t: 625, l: 968, w: 69, h: 74 },
        { imageIndex: 0, t: 625, l: 1047, w: 57, h: 74 },
        { imageIndex: 0, t: 625, l: 1107, w: 36, h: 74 },
        { imageIndex: 0, t: 625, l: 1147, w: 82, h: 74 },
        { imageIndex: 0, t: 625, l: 1238, w: 46, h: 74 },
        { imageIndex: 0, t: 625, l: 1293, w: 60, h: 74 },
      ],
    },
  ],
  //字错误列表
  errorZis: [
    {
      ziIndex: 10,
      type: "错别字",
      code: "Z001",
      zi: "圆",
      correct: "园",
      reason: "\"公园\"是供公众游览休息的园林，应使用\"园\"，而\"圆\"一般指圆形。",
      locations: [{ imageIndex: 0, t: 106, l: 858, w: 54, h: 69 }],
    },
    {
      ziIndex: 70,
      type: "错别字",
      code: "Z002",
      zi: "从",
      correct: "丛",
      reason: "\"花丛\"指丛生的花，\"丛\"有聚集、丛生之意，\"从\"无此用法。",
      locations: [{ imageIndex: 0, t: 366, l: 1290, w: 56, h: 71 }],
    },
    {
      ziIndex: 78,
      type: "错别字",
      code: "Z003",
      zi: "迫",
      correct: "追",
      reason: "\"追着它跑\"表达追赶的意思，\"追\"更符合语境，\"迫\"一般表示逼迫、强迫。",
      locations: [{ imageIndex: 0, t: 452, l: 545, w: 53, h: 74 }],
    },
    {
      ziIndex: 88,
      type: "错别字",
      code: "Z004",
      zi: "交",
      correct: "跤",
      reason: "\"摔了一跤\"是固定表达，\"跤\"指跟头，\"交\"无此用法。",
      locations: [{ imageIndex: 0, t: 454, l: 1178, w: 50, h: 74 }],
    },
    {
      ziIndex: 131,
      type: "错别字",
      code: "Z005",
      zi: "扑",
      correct: "铺",
      reason: "\"铺野餐垫\"表示把野餐垫展开、平放在地上，\"铺\"有展开、摊开之意，\"扑\"一般表示冲、拍打。",
      locations: [{ imageIndex: 0, t: 713, l: 555, w: 41, h: 71 }],
    },
    {
      ziIndex: 135,
      type: "错别字",
      code: "Z006",
      zi: "店",
      correct: "垫",
      reason: "此处应是\"野餐垫\"，\"垫\"指垫子，\"店\"指商店，不符合语境。",
      locations: [{ imageIndex: 0, t: 714, l: 794, w: 55, h: 71 }],
    },
    {
      ziIndex: 139,
      type: "错别字",
      code: "Z007",
      zi: "座",
      correct: "坐",
      reason: "\"坐\"表示把臀部放在椅子、凳子或其他物体上，支持身体重量，\"座\"一般作名词，指座位。",
      locations: [{ imageIndex: 0, t: 714, l: 1047, w: 55, h: 71 }],
    },
    {
      ziIndex: 159,
      type: "错别字",
      code: "Z008",
      zi: "陈",
      correct: "阵",
      reason: "\"一阵风\"是固定搭配，\"阵\"用于表示动作或现象经过的段落，\"陈\"无此用法。",
      locations: [{ imageIndex: 0, t: 799, l: 1054, w: 40, h: 73 }],
    },
    {
      ziIndex: 222,
      type: "错别字",
      code: "Z009",
      zi: "完",
      correct: "玩",
      reason: "\"玩沙子\"表示进行玩沙子的活动，\"玩\"有玩耍之意，\"完\"一般表示结束。",
      locations: [{ imageIndex: 0, t: 1150, l: 921, w: 59, h: 69 }],
    },
    {
      ziIndex: 237,
      type: "错别字",
      code: "Z010",
      zi: "到",
      correct: "倒",
      reason: "\"倒过来\"表示把物体颠倒过来，\"倒\"有颠倒、反转之意，\"到\"一般表示到达。",
      locations: [{ imageIndex: 0, t: 1236, l: 599, w: 67, h: 70 }],
    },
    {
      ziIndex: 294,
      type: "错别字",
      code: "Z011",
      zi: "叶",
      correct: "山",
      reason: "结合语境\"太阳快落山的时候\"更合理，\"山\"符合太阳落山的表达，\"叶\"不符合。",
      locations: [{ imageIndex: 0, t: 1496, l: 285, w: 54, h: 67 }],
    },
    {
      ziIndex: 338,
      type: "错别字",
      code: "Z012",
      zi: "圆",
      correct: "园",
      reason: "同前文\"公园\"的\"园\"，\"圆\"使用错误。",
      locations: [{ imageIndex: 0, t: 1749, l: 234, w: 53, h: 68 }],
    },
  ],
  //妙句列表
  goodJuZis: [
    {
      ziSIndex: 31,
      ziEIndex: 50,
      shangXi: "描写生动形象",
      reason: "通过列举\"红的、黄的、紫的\"等颜色，再用\"五颜六色\"进行总结，生动地描绘出公园里花的色彩丰富。",
      locations: [
        { imageIndex: 0, t: 276, l: 111, w: 57, h: 73 },
        { imageIndex: 0, t: 276, l: 177, w: 55, h: 73 },
        { imageIndex: 0, t: 276, l: 241, w: 52, h: 73 },
        { imageIndex: 0, t: 276, l: 303, w: 40, h: 73 },
        { imageIndex: 0, t: 276, l: 353, w: 66, h: 73 },
        { imageIndex: 0, t: 276, l: 428, w: 41, h: 73 },
        { imageIndex: 0, t: 276, l: 478, w: 55, h: 73 },
        { imageIndex: 0, t: 276, l: 542, w: 57, h: 73 },
        { imageIndex: 0, t: 276, l: 608, w: 50, h: 73 },
        { imageIndex: 0, t: 276, l: 667, w: 53, h: 73 },
        { imageIndex: 0, t: 276, l: 729, w: 54, h: 73 },
        { imageIndex: 0, t: 276, l: 793, w: 66, h: 73 },
        { imageIndex: 0, t: 276, l: 866, w: 36, h: 73 },
        { imageIndex: 0, t: 276, l: 909, w: 61, h: 73 },
        { imageIndex: 0, t: 276, l: 980, w: 66, h: 73 },
        { imageIndex: 0, t: 276, l: 1053, w: 36, h: 73 },
        { imageIndex: 0, t: 276, l: 1096, w: 76, h: 73 },
        { imageIndex: 0, t: 276, l: 1181, w: 40, h: 73 },
        { imageIndex: 0, t: 276, l: 1231, w: 54, h: 73 },
        { imageIndex: 0, t: 276, l: 1295, w: 68, h: 73 },
      ],
    },
    {
      ziSIndex: 291,
      ziEIndex: 318,
      shangXi: "运用比喻的修辞手法",
      reason: "将\"天上金黄色的云\"比作\"妈妈煎的鸡蛋饼\"，形象地写出了云的颜色和形状特点，富有画面感。",
      locations: [
        { imageIndex: 0, t: 1496, l: 109, w: 41, h: 67 },
        { imageIndex: 0, t: 1496, l: 159, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 222, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 285, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 348, w: 65, h: 67 },
        { imageIndex: 0, t: 1496, l: 421, w: 42, h: 67 },
        { imageIndex: 0, t: 1496, l: 471, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 534, w: 46, h: 67 },
        { imageIndex: 0, t: 1496, l: 588, w: 74, h: 67 },
        { imageIndex: 0, t: 1496, l: 671, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 734, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 797, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 860, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 923, w: 41, h: 67 },
        { imageIndex: 0, t: 1496, l: 972, w: 65, h: 67 },
        { imageIndex: 0, t: 1496, l: 1046, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 1109, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 1172, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 1235, w: 32, h: 67 },
        { imageIndex: 0, t: 1496, l: 1276, w: 80, h: 67 },
        { imageIndex: 0, t: 1577, l: 105, w: 49, h: 72 },
        { imageIndex: 0, t: 1577, l: 164, w: 56, h: 72 },
        { imageIndex: 0, t: 1577, l: 229, w: 56, h: 72 },
        { imageIndex: 0, t: 1577, l: 295, w: 56, h: 72 },
        { imageIndex: 0, t: 1577, l: 360, w: 57, h: 72 },
        { imageIndex: 0, t: 1577, l: 426, w: 47, h: 72 },
        { imageIndex: 0, t: 1577, l: 482, w: 47, h: 72 },
        { imageIndex: 0, t: 1577, l: 539, w: 35, h: 72 },
      ],
    },
  ],
  imageInfos: [
    {
      imageId: "206369685057441792",
      imageUrl:
        "http://jzsw-oss.oss-cn-hangzhou.aliyuncs.com/composition/precorrect/206369685057441792.png?Expires=1749288767&OSSAccessKeyId=LTAI5tD6yCs8UPAHEVpbZ6HB&Signature=MgxQLStw0evww9H0qMH0hxY2Clo%3D",
    },
  ],
  pingYu:
    "这篇作文围绕周末公园游记展开，主题明确，内容较为丰富，详细描述了在公园的各种活动，如看花、追蝴蝶、野餐、玩沙子等，充满了生活气息。文中运用了比喻的修辞手法，如\"天上的云变成了金黄色，像妈妈煎的鸡蛋饼\"，使描写更加生动形象。不过，作文中存在较多错别字和标点使用不当的问题，如\"公圆\"\"摔了一交\"等，影响了文章的质量。关联词的使用也存在一些小瑕疵。希望作者在今后的写作中更加细心，减少错误，进一步提升写作水平。",
  score: 60.0,
  //修辞列表
  xiuCis: [
    {
      ziSIndex: 291,
      ziEIndex: 318,
      type: "比喻",
      code: "XC001",
      reason: "把\"天上金黄色的云\"比作\"妈妈煎的鸡蛋饼\"，生动形象地描绘出云的颜色和形状，让读者更直观地感受到云的特点。",
      locations: [
        { imageIndex: 0, t: 1496, l: 109, w: 41, h: 67 },
        { imageIndex: 0, t: 1496, l: 159, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 222, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 285, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 348, w: 65, h: 67 },
        { imageIndex: 0, t: 1496, l: 421, w: 42, h: 67 },
        { imageIndex: 0, t: 1496, l: 471, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 534, w: 46, h: 67 },
        { imageIndex: 0, t: 1496, l: 588, w: 74, h: 67 },
        { imageIndex: 0, t: 1496, l: 671, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 734, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 797, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 860, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 923, w: 41, h: 67 },
        { imageIndex: 0, t: 1496, l: 972, w: 65, h: 67 },
        { imageIndex: 0, t: 1496, l: 1046, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 1109, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 1172, w: 54, h: 67 },
        { imageIndex: 0, t: 1496, l: 1235, w: 32, h: 67 },
        { imageIndex: 0, t: 1496, l: 1276, w: 80, h: 67 },
        { imageIndex: 0, t: 1577, l: 105, w: 49, h: 72 },
        { imageIndex: 0, t: 1577, l: 164, w: 56, h: 72 },
        { imageIndex: 0, t: 1577, l: 229, w: 56, h: 72 },
        { imageIndex: 0, t: 1577, l: 295, w: 56, h: 72 },
        { imageIndex: 0, t: 1577, l: 360, w: 57, h: 72 },
        { imageIndex: 0, t: 1577, l: 426, w: 47, h: 72 },
        { imageIndex: 0, t: 1577, l: 482, w: 47, h: 72 },
        { imageIndex: 0, t: 1577, l: 539, w: 35, h: 72 },
      ],
    },
  ],
};

/**
 * 从批改结果中筛选错别字并按canvas分组
 * @param {Object} correctionData 批改结果数据
 * @returns {Array} 按canvas分组的错别字数据数组
 */
function filterErrorCharsByCanvas(correctionData = obj) {
  const canvasGroups = {}
  
  // 遍历所有错别字，保持原格式
  correctionData.errorZis.forEach(errorZi => {
    // 遍历每个错别字的所有位置
    errorZi.locations.forEach(location => {
      const { imageIndex } = location
      
      // 初始化canvas组如果不存在
      if (!canvasGroups[imageIndex]) {
        canvasGroups[imageIndex] = []
      }
      
      // 直接使用原本的errorZi格式，不进行转换
      canvasGroups[imageIndex].push(errorZi)
    })
  })
  
  // 遍历所有标点错误，保持原格式
  correctionData.errorBiaoDians.forEach(errorBiaoDian => {
    // 遍历每个标点错误的所有位置
    errorBiaoDian.locations.forEach(location => {
      const { imageIndex } = location
      
      // 初始化canvas组如果不存在
      if (!canvasGroups[imageIndex]) {
        canvasGroups[imageIndex] = []
      }
      
      // 直接使用原本的errorBiaoDian格式，不进行转换
      canvasGroups[imageIndex].push(errorBiaoDian)
    })
  })
  
  // 遍历所有妙句，保持原格式
  correctionData.goodJuZis.forEach(goodJuZi => {
    // 遍历每个妙句的所有位置
    goodJuZi.locations.forEach(location => {
      const { imageIndex } = location
      
      // 初始化canvas组如果不存在
      if (!canvasGroups[imageIndex]) {
        canvasGroups[imageIndex] = []
      }
      
      // 直接使用原本的goodJuZi格式，不进行转换
      canvasGroups[imageIndex].push(goodJuZi)
    })
  })
  
  // 转换为数组格式，确保索引连续
  const result = []
  const maxCanvasIndex = Math.max(...Object.keys(canvasGroups).map(Number))
  
  for (let i = 0; i <= maxCanvasIndex; i++) {
    if (canvasGroups[i]) {
      // 去重处理，因为一个错误可能有多个location但imageIndex相同
      const uniqueErrors = []
      const seenKeys = new Set()
      
      canvasGroups[i].forEach(error => {
        // 使用不同的key来区分错别字、标点错误和妙句
        let key
        if (error.ziIndex !== undefined) {
          key = `zi_${error.ziIndex}`
        } else if (error.ziSIndex !== undefined && error.ziEIndex !== undefined) {
          key = `bd_${error.ziSIndex}_${error.ziEIndex}`
        } else {
          key = `gj_${error.ziSIndex}_${error.ziEIndex}` // 妙句key
        }
        
        if (!seenKeys.has(key)) {
          seenKeys.add(key)
          uniqueErrors.push(error)
        }
      })
      
      result.push([{
        text: `作文第${i + 1}页批改`,
        chars: uniqueErrors  // 包含错别字、标点错误和妙句
      }])
    } else {
      // 如果某个canvas没有错误，返回空数组
      result.push([{
        text: `作文第${i + 1}页`,
        chars: []
      }])
    }
  }
  
  return result
}

/**
 * 计算每个canvas的统计信息
 * @param {Array} canvasDataArray 按canvas分组的数据数组
 * @returns {Array} 每个canvas的统计信息数组
 */
function calculateCanvasStats(canvasDataArray) {
  return canvasDataArray.map(canvasData => {
    let correct = 0
    let incorrect = 0
    let missing = 0
    let goodSentences = 0 // 新增妙句统计
    
    canvasData.forEach(item => {
      if (item.chars && Array.isArray(item.chars)) {
        item.chars.forEach(char => {
          // 适配原本的errorZis、errorBiaoDians和goodJuZis格式
          if (char.type === "错别字" || 
              (char.type && (char.type.includes('标点') || 
                             char.type === '对话标点缺失' || 
                             char.type === '标点使用不当'))) {
            incorrect++
          } else if (char.shangXi !== undefined || 
                     (char.type && char.type.includes('妙句'))) {
            goodSentences++
          } else if (char.type === "正确") {
            correct++
          } else if (char.type === "漏写") {
            missing++
          }
        })
      }
    })
    
    return { correct, incorrect, missing, goodSentences }
  })
}

/**
 * 获取图片URL列表
 * @param {Object} correctionData 批改结果数据
 * @returns {Array} 图片URL数组
 */
function getImageUrls(correctionData = obj) {
  return correctionData.imageInfos.map(info => info.imageUrl)
}

// 导出方法和数据
export default obj
export { 
  filterErrorCharsByCanvas, 
  calculateCanvasStats, 
  getImageUrls 
}
